<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style-type: none;
        }
        .container {
            display: flex;
            justify-content: center;
            flex-direction: column;
            width: 500px;
            height: 200px;
            border: 1px solid #000;
        }
        .container form {
            height: 100px;
            width: 100px;
            margin: 0 auto;
            /* border: 1px solid #000; */
        }
        .container form div {
            display: flex;
            align-items: center;
            justify-content: left;
            /* border: 1px solid #000; */
        }
        .btn {
            margin-top: 20px;
            display: flex;
            /* border: 1px solid #000; */
            justify-content: center;
        }
    </style>
</head>
<body>
    <div class="container">
        <form action="#" method="GET">
            <div><input type="checkbox" name="insterst">玩游戏</div>
            <div><input type="checkbox" name="insterst">看电影</div>
            <div><input type="checkbox" name="insterst">听歌</div>
            <div><input type="checkbox" name="insterst">看电视</div>
        </form>
        <div class="btn">
            <button>全选</button>
            <button>全不选</button>
            <button>反选</button>
        </div>
    </div>
    <script>
        let btns = document.querySelectorAll('.btn button');
        console.log(btns);
        let ins = document.querySelectorAll('input');
        console.log(ins);
        let inserte = document.getElementsByName('insterst');
        console.log(inserte);
        //这是查看checkbox的一个状态
        for (let i = 0; i < ins.length; i++) {
            console.log(ins[i].checked);
        }
        //这是全选的一个操作
        btns[0].onclick = function () {
            for (let i = 0; i < ins.length; i++) {
                if (ins[i].checked === false) {
                    ins[i].checked = true
                }
            }
        }
        //这是全不选的一个操作
        btns[1].onclick = function () {
            for (let i = 0; i < ins.length; i++) {
                if (ins[i].checked === true) {
                    ins[i].checked = false
                }
            }
        }
        //这是反选的一个操作
        btns[2].onclick = function () {
            for (let i = 0; i < ins.length; i++) {
                if (ins[i].checked === true) {
                    ins[i].checked = false
                } else {
                    ins[i].checked = true
                }
            }
        }
    </script>
</body>
</html>